
#ifndef _TTG_EXTRAS_XMLTREE_
#define _TTG_EXTRAS_XMLTREE_
#include "Common/Definitions.h"

//#include <windows.h>

#include <list>
#include "Common/Errors.h"
#include "Common/Math.h"
#include "Common/Structures.h"

namespace ttg
{
	namespace extras
	{
		class XMLTree :public structures::NamedObject
		{
			private:
				std::list<XMLTree *> explorers;
				bool isexplorer;
			protected:
				bool isExplorer();
				void addExplorer(XMLTree *tree);
				void removeExplorer(XMLTree *tree);
				std::list<XMLTree *> *getExplorers();
				XMLTree(const char *name, std::list<XMLTree *> *explorers);
				XMLTree(const char *name);
			public:
				//Access to target file.
				enum AccessType
				{
					XML_RO = 1,	//Defines read-only XMLTree. For loading.
					XML_WO = 2	//Defines write-only XMLTree. For saving.
				};
				//--- control actions ---
				//Assigns current XMLTree with given file.
				//Note:  in case of any errors it throws IOError.
				virtual void assign(AccessType access, const char *filename) = 0;
				//Releases loaded tree or saves new tree.
				virtual void close() = 0;
				//Returns explorer. It can explore the same tree independently.
				//Note: All explorers will be released automatically. Manual release is allowed.
				virtual XMLTree &getSubXMLTree() = 0;
				virtual void resetIterators() = 0;
				//ro actions
				//Opens section with given name.
				//Note: This call makes unavaible using of openNextSection() for current section.
				virtual bool openSection(const char *section) = 0;
				//Closes current section.
				virtual bool closeSection() = 0;
				//Opens next section.
				//Note: This call makes unavaible using of openSection() for current section.
				virtual bool openNextSection() = 0;
				//Returns name of the current section.
				virtual const char *getCurrentSection() = 0;
				//Returns count of subsections.
				virtual size_t getSubSectionCount() = 0;
				//Returns subsections as dictionary with references.
				virtual structures::Dictionary<XMLTree> *getSubSections() = 0;
				//Returns count of attributes.
				virtual size_t getAttributeCount() = 0;
				//Returns string value of the attribute with given name.
				virtual bool getStringAttribute(const char *attr, const char *&val) = 0;
				//Returns int value of the attribute with given name.
				virtual bool getIntAttribute(const char *attr, int &val);
				//Returns int value of the attribute with given name.
				virtual bool getDWORDAttribute(const char *attr, DWORD &val);
				//Returns float value of the attribute with given name.
				virtual bool getFloatAttribute(const char *attr, float &val);
				//Returns double value of the attribute with given name.
				virtual bool getDoubleAttribute(const char *attr, double &val);
				//Returns bool value of the attribute with given name.
				virtual bool getBoolAttribute(const char *attr, bool &val);
				//Returns vec3f value of the attribute with given name.
				virtual bool getVec3fAttribute(const char *attr, math::vec3f &val);
				//Returns col4f value of the attribute with given name.
				virtual bool getCol4fAttribute(const char *attr, col4f &val);
				//Return next attribute.
				virtual bool getNextAttribute(const char *&attr, const char *&val) = 0;
				//rw actions
				//Adds empty section, but doesn't open it.
				//Note: it can throw DeniedActionError.
				virtual void addSection(const char *section) = 0;
				//Adds empty section and opens it.
				//Note: it can throw DeniedActionError.
				virtual void addSectionAndOpen(const char *section) = 0;
				//Adds string attribute to current section.
				//Note: it can throw DeniedActionError.
				virtual void addStringAttribute(const char *attr, const char *val) = 0;
				//Adds int attribute to current section.
				//Note: it can throw DeniedActionError.
				void addIntAttribute(const char *attr, int val);
				//Adds DWORD attribute to current section.
				//Note: it can throw DeniedActionError.
				void addDWORDAttribute(const char *attr, DWORD val);
				//Adds float attribute to current section.
				//Note: it can throw DeniedActionError.
				void addFloatAttribute(const char *attr, float val);
				//Adds double attribute to current section.
				//Note: it can throw DeniedActionError.
				void addDoubleAttribute(const char *attr, double val);
				//Adds bool attribute to current section.
				//Note: it can throw DeniedActionError.
				void addBoolAttribute(const char *attr, bool val);
				//Adds vec3f attribute to current section.
				//Note: it can throw DeniedActionError.
				void addVec3fAttribute(const char *attr, const math::vec3f &val);
				//Adds col4f attribute to current section.
				//Note: it can throw DeniedActionError.
				void addCol4fAttribute(const char *attr, const col4f &val);
				//XMLTree, You Are Free !!!
				virtual ~XMLTree();
		};
	}
}

#endif
